package com.note7_6;

import java.io.*;

public class Question0 {

	/*
	 * 按照刚才读取的模板文件pet. template的模板格式保存宠物数据到文本文件
	 * 即把{name}、{type}、{master}替换为具体的宠物信息
	 * 将替换后的内容写入到C:\myDoc\pet.txt中
	 */
	public static void main(String[] args){
		BufferedReader bfr = null;
		BufferedWriter bfw = null;
		try {
			bfr = new BufferedReader(new FileReader("src/com/pet.template"));
			char[] ch = new char[100];
			int len = -1;
			String str = null;
			while((len = bfr.read(ch)) != -1){
				str = new String(ch,0,len);
				System.out.println(str);
			}
			str = str.replace("{name}", "欧欧");
			str = str.replace("{type}", "狗狗");
			str = str.replace("{master}","阿炊");
			System.out.println(str);
			bfw = new BufferedWriter(new FileWriter("src/com/pet1.template"));
			bfw.write(str);
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			if(bfr != null){
				try {
					bfr.close();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			if(bfw != null){
				try {
					bfw.close();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
	}
}
